package com.societyGames.codeAlong.state.codeExercise.model
{
import com.societyGames.codeAlong.state.codeExercise.model.link.IHyperText;
import com.societyGames.codeAlong.state.codeExercise.model.link.ILinkable;

public class FunctionParameterData implements ILinkable, IHyperText
	{
		private static const _parameterId:String = "parameter";
		private var _parent:ILinkable;
		public var name:String;
		public var index:int;
		public var type:String;
		public var defaultValue:String;
		public var description:String;
		
		public function FunctionParameterData()
		{	
		}
		
		//IHyperText-->		
		public function toHyperText():String
		{
			var text:String = "<b>" + name + "</b>"
              + (this.type.length > 0 ? ":" + this.type : "")
              + (this.defaultValue.length > 0 ? "=" + defaultValue : "")
              + " " + description;
			return text;
		}
		//<--IHyperText
		
		//ILinkable-->
		public function toLink():String
		{
			return this._parent.toLink() + LibraryData.separator + _parameterId + LibraryData.separator + this.name;
		}
		//<--ILinkable
		
		public static function fromXml(parent:ILinkable, xml:XML):FunctionParameterData
		{
			var parameterData:FunctionParameterData = new FunctionParameterData();
			parameterData._parent = parent;
			parameterData.name = xml.@name;
			parameterData.index = int(xml.@index) - 1;
			parameterData.type = xml.@type;
			parameterData.description = xml.@description;
			parameterData.defaultValue = xml["@default"];
			return parameterData;	
		}
	}
}